package com.chenl.provider.controller;

import cn.hutool.json.JSONObject;
import cn.hutool.json.XML;
import com.chenl.provider.util.HttpUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class TestCon2 {



    public static void main(String[] args) {
        StringBuffer xmlStr = new StringBuffer();
        xmlStr.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:zy=\"http://tempuri.org/ZY_WS_MB_MSP\">\n" +
                "   <soapenv:Header/>\n" +
                "   <soapenv:Body>\n" +
                "      <zy:req>\n" +
                "         <cString><![CDATA[");
        //动态参数
        xmlStr.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\n" +
                "<Msg>\n" +
                "    <Head>\n" +
                "       <Id>318bc18d-4a01-463b-9bf7-085787c7d40c</Id>  \n" +
                "       <Name>业务中台库存查询</Name>\n" +
                "       <Source>ZYYWZT</Source> \n" +
                "       <Target>LYERP</Target>\n" +
                "       <SerName>ywzt_ly_stockList</SerName>\n" +
                "       <MsgType>1</MsgType> \n" +
                "       <RtCode></RtCode> \n" +
                "       <RtDesc></RtDesc> \n" +
                "       <Backup1></Backup1> \n" +
                "       <Backup2></Backup2> \n" +
                "       <Backup3></Backup3> \n" +
                "       <Backup4></Backup4> \n" +
                "       <Backup5></Backup5> \n" +
                "       <Date>2023-03-27 11:44:49</Date> \n" +
                "       <Attrs>\n" +
                "           <Attr>86081</Attr>\n" +
                "       </Attrs>\n" +
                "    </Head>\n" +
                "</Msg>");
        xmlStr.append( "]]></cString>\n" +
                "      </zy:req>\n" +
                "   </soapenv:Body>\n" +
                "</soapenv:Envelope>");
        System.out.println(xmlStr.toString());
        String s = HttpUtils.sendWstXml(xmlStr.toString(), "https://10.190.7.89:7901/WSMBService");
        System.out.println(s);
    }
    private static void buildParam(StringBuilder paramStr, Map<String, Object> params) {
        List<Map.Entry<String, Object>> list = params.entrySet().stream().collect(Collectors.toList());
        for (int i = 0; i < list.size(); i++) {
            Map.Entry<String, Object> entry = list.get(i);
            String key = entry.getKey();
            String value = String.valueOf(entry.getValue());
            paramStr.append("<Param neme=\""+key+"\" ");
            if (i<list.size()-1){
                paramStr.append("value=\""+value+"\" />\n        ");
            }else {
                paramStr.append("value=\""+value+"\" />\n");
            }
        }
    }
  /*  static String resultStr="<Msg>" +
            "<Head>" +
            "<Name>库存查询</Name>" +
            "<Source></Source>" +
            "<Target></Target>" +
            "<SerName></SerName>" +
            "<MsgType>0</MsgType>" +
            "<RtCode/>" +
            "<RtDesc/>" +
            "<Date>2023/01/1808:00:00</Date>" +
            "<Values>" +
            "<Value CompanyId=\"123\"SkuId=\"1\"SkuCode=\"123\"PackingUnit=\"123\"ItemStatus=\"123\"WarehouseId=\"123\"ItemType=\"123\"SkuQuantity=\"123\">测试</Value>" +
            "<Value CompanyId=\"123\"SkuId=\"2\"SkuCode=\"123\"PackingUnit=\"123\"ItemStatus=\"123\"WarehouseId=\"123\"ItemType=\"123\"SkuQuantity=\"123\"/>" +
            "<Value CompanyId=\"123\"SkuId=\"3\"SkuCode=\"123\"PackingUnit=\"123\"ItemStatus=\"123\"WarehouseId=\"123\"ItemType=\"123\"SkuQuantity=\"123\"/>" +
            "<Value CompanyId=\"123\"SkuId=\"4\"SkuCode=\"123\"PackingUnit=\"123\"ItemStatus=\"123\"WarehouseId=\"123\"ItemType=\"123\"SkuQuantity=\"123\"/>" +
            "</Values>" +
            "</Head>" +
            "</Msg>";
    public static void main(String[] args) {
        List<Map> maps = buildStockResult(resultStr);
        System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(maps));
    }
    private static List<Map> buildStockResult(String resultStr) {
        List<Map> resDtos=new ArrayList<>();
        JSONObject jsonObject = XML.toJSONObject(resultStr);
        if (jsonObject.getJSONObject("Msg")!=null&&jsonObject.getJSONObject("Msg").getJSONObject("Head")!=null&&jsonObject.getJSONObject("Msg").getJSONObject("Head").getStr("Values")!=null){
            String valueStr = jsonObject.getJSONObject("Msg").getJSONObject("Head").getJSONObject("Values").getStr("Value");
            if (StringUtils.isNotBlank(valueStr)){
                resDtos = com.alibaba.fastjson.JSONObject.parseArray(valueStr, Map.class);
            }
        }
        return resDtos;
    }*/
}
